package com.yxt.admin.handler;

import com.yxt.admin.exception.user.CaptchaException;
import com.yxt.admin.exception.user.CaptchaExpireException;
import com.yxt.admin.exception.user.UserNameAndPasswordException;
import com.yxt.common.utils.ajax.R;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;


@Slf4j
@RestControllerAdvice
public class AdminExceptionHandler {
    @ExceptionHandler(value = {CaptchaException.class})
    public R handleCaptchaException(CaptchaException exception){
        return R.error( exception.getCode(), exception.getDefaultMessage());
    }

    @ExceptionHandler(value = {CaptchaExpireException.class})
    public R handleCaptchaExpireException(CaptchaExpireException exception){
        return R.error(exception.getCode(), exception.getDefaultMessage());
    }

    @ExceptionHandler(value = {UserNameAndPasswordException.class})
    public R handleUserNameAndPasswordException(UserNameAndPasswordException exception){
        return R.error(exception.getCode(), exception.getDefaultMessage());
    }
}
